package com.course.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;
import java.util.Vector;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.BeanUtils;

import com.course.bean.SolutionTo;
import com.course.delegate.SolutionMgrDelegate;
import com.course.exception.DataNotFoundException;
import com.course.formbean.SolutionFormBean;
import com.course.util.UtilConstants;



public class ViewQueryStatusAction extends HttpServlet {

	
	private static final long serialVersionUID = 1L;
public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
               doPost(request, response);
               }
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
      SolutionFormBean sb=new SolutionFormBean();
		Map map=request.getParameterMap();
	try {
		BeanUtils.populate(sb, map);
	} catch (IllegalAccessException e1) {
		// TODO Auto-generated catch block
		e1.printStackTrace();
	} catch (InvocationTargetException e1) {
		// TODO Auto-generated catch block
		e1.printStackTrace();
		}
        String path="";
        Vector<SolutionTo> queryStatus=null;

	  try{
		  String login=request.getParameter("from");
		  try{
		  queryStatus= new SolutionMgrDelegate().getQueryStatus(login);
		  }catch (DataNotFoundException e) {
			e.printStackTrace();
		}
		  
		  System.out.println("in Action class vcb..........."+queryStatus);
		  if(!queryStatus.isEmpty()){
			  request.setAttribute("Statusvector", queryStatus);
			  request.setAttribute("status", UtilConstants._QUERY_STATUS);
			  path=UtilConstants._DISPLAY_QUERY_STATUS;
			 }
		  else {
			  request.setAttribute("status", UtilConstants._NO_QUERY_STATUS);
			  path=UtilConstants._DISPLAY_QUERY_STATUS;
			}
		}
	  catch (NullPointerException e) {
		  request.setAttribute("status", UtilConstants._INVALIED_DATA);
		  path=UtilConstants._DISPLAY_QUERY_STATUS;
		e.printStackTrace();
		}
  RequestDispatcher rd=request.getRequestDispatcher(path);
		rd.forward(request,response);

	}

}
